//
//  GRStoreAnnotationView.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/8/30.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRStoreAnnotationView.h"
#import "GRStoreAnnotation.h"
#import "GRStoreCusCalloutView.h"
#define kWidth         25.f
#define kHeight         25.f
#define kCalloutWidth   60.0
#define kCalloutHeight  21.0

@interface GRStoreAnnotationView()
@property(nonatomic,strong)GRStoreCusCalloutView * calloutView;
@end

@implementation GRStoreAnnotationView
@synthesize imageView = _imageView;

-(id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if(self ){
        [self setBounds:CGRectMake(0.f, 0.f, 25, 25)];
        [self setBackgroundColor:[UIColor clearColor]];
        
        self.imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        [self addSubview:self.imageView];
        self.calloutView = [[GRStoreCusCalloutView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
        self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                              -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        [self addSubview:self.calloutView];
    }
    return self;
        
}

-(void)updateImageView{
    if ([self.annotation isKindOfClass:[GRStoreAnnotation class]]) {
        [self.imageView setImage:[UIImage imageNamed:@"store_02"]];
         self.calloutView.titleLabel.text = self.annotation.title;
        
    }else{
        [self.imageView setImage:[UIImage imageNamed:@"store_01"]];
        self.calloutView.titleLabel.text = @"我的位置";
    }
}
-(void)setAnnotation:(id<MAAnnotation>)annotation{
    
    [super setAnnotation:annotation];
    [self updateImageView];
}


@end
